﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace Mimoza.PuttyPlugin
{
    public enum Type
    {
        Telnet = 0,
        SSH = 1
    };

    public class WindowSize
    {
        public int Columns = 80;
        public int Rows = 24;
    };

    public class Scrollback
    {
        public int ScrollbarLines = 200;
        public bool IsShowScrollbarFullScreen = true;
    };

    public class PuttyData
    {
        public string SessionName
        {
            get { return m_sessionName; }
            set { m_sessionName = value; }
        }

        public bool IsStartOnStartup
        {
            get { return m_bIsStartOnStartup; }
            set { m_bIsStartOnStartup = value; }
        }

        public string Computer
        {
            get { return m_computer; }
            set { m_computer = value; }
        }

        public int Port
        {
            get { return m_port; }
            set { m_port = value; }
        }

        public Type Type
        {
            get { return m_type; }
            set { m_type = value; }
        }

        public string UserName
        {
            get { return m_userName; }
            set { m_userName = value; }
        }

        public WindowSize WindowSize
        {
            get { return m_size; }
            set { m_size = value; }
        }

        public Scrollback Scrollback
        {
            get { return m_scrollback; }
            set { m_scrollback = value; }
        }

        public string Serialize()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(PuttyData));
            TextWriter text = new StringWriter();
            serializer.Serialize(text, this);
            return text.ToString();
        }

        public static PuttyData Deserialize(string data)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(PuttyData));
            using (TextReader text = new StringReader(data))
            {
                return deserializer.Deserialize(text) as PuttyData;
            }
        }
        
        string m_computer = "";
        int m_port = 22;
        Type m_type = Type.SSH;
        string m_userName = "";
        
        string m_sessionName = "";
        bool m_bIsStartOnStartup = false;

        WindowSize m_size = new WindowSize();
        Scrollback m_scrollback = new Scrollback();
    }
}
